package github.kawaiior.yuanchuxiuzhen.common.entity.addon.model;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import github.kawaiior.yuanchuxiuzhen.common.entity.addon.ThunderFieldCrocodileEntity;
import github.kawaiior.yuanchuxiuzhen.util.RenderUtil;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.util.math.MathHelper;

public class ThunderFieldCrocodileEntityModel extends EntityModel<ThunderFieldCrocodileEntity> {
    private final ModelRenderer body;
    
    private final ModelRenderer head;
    
    private final ModelRenderer rightarm;
    
    private final ModelRenderer rightarm2;
    
    private final ModelRenderer leftarm;
    
    private final ModelRenderer leftarm2;
    
    private final ModelRenderer rightleg;
    
    private final ModelRenderer rightleg2;
    
    private final ModelRenderer leftleg;
    
    private final ModelRenderer leftleg2;

    public ThunderFieldCrocodileEntityModel(){
        this.textureWidth=128;
        this.textureHeight=128;
        this.body=new ModelRenderer(this);
        this.body.setRotationPoint(0.0F,24.0F,0.0F);
        addBox(this.body, 32, 44, -10.0F, -17.0F, -8.0F, 20, 14, 16, 0.0F, false);
        addBox(this.body, 0, 74, -9.0F, -15.0F, 8.0F, 18, 12, 12, 0.0F, false);
        addBox(this.body, 0, 98, -7.0F, -14.0F, 20.0F, 14, 11, 11, 0.0F, false);
        addBox(this.body, 60, 74, -5.0F, -13.0F, 31.0F, 10, 9, 11, 0.0F, false);
        addBox(this.body, 50, 94, -4.0F, -12.0F, 42.0F, 8, 7, 11, 0.0F, false);
        addBox(this.body, 50, 112, -3.0F, -11.0F, 53.0F, 6, 5, 8, 0.0F, false);
        addBox(this.body, 51, 74, -2.0F, -10.0F, 61.0F, 4, 3, 6, 0.0F, false);
        addBox(this.body, 44, 20, -9.0F, -16.0F, -20.0F, 18, 12, 12, 0.0F, false);
        addBox(this.body, 56, 0, -7.0F, -15.0F, -30.0F, 14, 10, 10, 0.0F, false);
        this.head=new ModelRenderer(this);
        this.head.setRotationPoint(0.1F,15.5F,-30.0F);
        addBox(this.head, 88, 44, -7.1F, -7.5F, -4.0F, 14, 12, 4, 0.0F, false);
        addBox(this.head, 0, 0, -8.1F, -8.5F, -16.0F, 16, 13, 12, 0.0F, false);
        addBox(this.head, 0, 25, -6.1F, -5.5F, -20.0F, 12, 10, 4, 0.0F, false);
        addBox(this.head, 0, 39, -5.1F, -4.5F, -26.0F, 10, 8, 6, 0.0F, false);
        addBox(this.head, 0, 53, -3.6F, -3.5F, -34.0F, 7, 6, 8, 0.0F, false);
        this.rightarm=new ModelRenderer(this);
        this.rightarm.setRotationPoint(-7.0F,16.0F,-18.0F);
        RenderUtil.setRotationAngle(this.rightarm,0.0F,0.0F,0.5236F);
        addBox(this.rightarm, 94, 64, -5.0F, -2.0F, -5.0F, 5, 10, 10, 0.0F, false);
        this.rightarm2=new ModelRenderer(this);
        this.rightarm2.setRotationPoint(0.0F,8.0F,0.0F);
        RenderUtil.setRotationAngle(this.rightarm2,0.0F,0.3491F,-0.5236F);
        this.rightarm.addChild(this.rightarm2);
        addBox(this.rightarm2, 88, 94, -8.0F, -3.0F, -12.0F, 8, 4, 12, 0.0F, false);
        this.leftarm=new ModelRenderer(this);
        this.leftarm.setRotationPoint(7.0F,16.0F,-18.0F);
        RenderUtil.setRotationAngle(this.leftarm,0.0F,0.0F,-0.5236F);
        addBox(this.leftarm, 94, 64, 0.0F, -2.0F, -5.0F, 5, 10, 10, 0.0F, false);
        this.leftarm2=new ModelRenderer(this);
        this.leftarm2.setRotationPoint(0.0F,8.0F,0.0F);
        RenderUtil.setRotationAngle(this.leftarm2,0.0F,-0.3491F,0.5236F);
        this.leftarm.addChild(this.leftarm2);
        addBox(this.leftarm2, 88, 94, 0.0F, -3.0F, -12.0F, 8, 4, 12, 0.0F, false);
        this.rightleg=new ModelRenderer(this);
        this.rightleg.setRotationPoint(-7.0F,16.0F,20.0F);
        RenderUtil.setRotationAngle(this.rightleg,0.0F,0.0F,0.5236F);
        addBox(this.rightleg, 94, 64, -5.0F, -2.0F, -5.0F, 5, 10, 10, 0.0F, false);
        this.rightleg2=new ModelRenderer(this);
        this.rightleg2.setRotationPoint(0.0F,8.0F,0.0F);
        RenderUtil.setRotationAngle(this.rightleg2,0.0F,0.5236F,-0.5236F);
        this.rightleg.addChild(this.rightleg2);
        addBox(this.rightleg2, 88, 94, -8.0F, -3.0F, -12.0F, 8, 4, 12, 0.0F, false);
        this.leftleg=new ModelRenderer(this);
        this.leftleg.setRotationPoint(7.0F,16.0F,20.0F);
        RenderUtil.setRotationAngle(this.leftleg,0.0F,0.0F,-0.5236F);
        addBox(this.leftleg, 94, 64, 0.0F, -2.0F, -5.0F, 5, 10, 10, 0.0F, false);
        this.leftleg2=new ModelRenderer(this);
        this.leftleg2.setRotationPoint(0.0F,8.0F,0.0F);
        RenderUtil.setRotationAngle(this.leftleg2,0.0F,-0.5236F,0.5236F);
        this.leftleg.addChild(this.leftleg2);
        addBox(this.leftleg2, 88, 94, 0.0F, -3.0F, -12.0F, 8, 4, 12, 0.0F, false);
        
        
    }

    private void addBox(ModelRenderer mb, int tx, int ty, float x, float y, float z, float width, float height, float depth, float delta, boolean mirrorIn){
        ModelRenderer mr = new ModelRenderer(this);
        mb.addChild(mr);
        mr.setTextureOffset(tx, ty).addBox(x,y,z,width,height,depth,delta,mirrorIn);
    }

    @Override
    public void setRotationAngles(ThunderFieldCrocodileEntity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
        this.head.rotateAngleY = netHeadYaw / 57.295776F;
        this.head.rotateAngleX = headPitch / 57.295776F;
        this.rightleg.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * -1.0F * limbSwingAmount;
        this.rightarm.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * 1.0F * limbSwingAmount;
        this.leftleg.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * 1.0F * limbSwingAmount;
        this.leftarm.rotateAngleX = MathHelper.cos(limbSwing * 1.0F) * -1.0F * limbSwingAmount;
    }

    @Override
    public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
        this.body.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.head.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.rightarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.leftarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.rightleg.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.leftleg.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
    }
}